﻿#region zh-CHS 2006 - 2007 DemoSoft 团队 | en 2006 - 2007 DemoSoft Team

//     NOTES
// ---------------
//
// This file is a part of the G.O.S.E(Game Online Server Engine) for .NET.
//
//                 2006-2007 DemoSoft Team
//
//
// First Version : by H.Q.Cai - mailto:caihuanqing@hotmail.com

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as published
 *   by the Free Software Foundation; either version 2.1 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

#region zh-CHS 包含名字空间 | en Include namespace
using System;
using Demo_G.O.S.E.ServerEngine.World;
#endregion

namespace Demo_G.O.S.E.ServerEngine.Util
{
    ///// <summary>
    //ServerSliceTimer 是游戏世界里的时间片
    ///// </summary>
    //class ServerSliceTimer
    //{
    //    #region zh-CHS 枚举 | en enum
    //    public enum Priorities
    //    {
    //        Millisecond = 0,
    //        Millisecond10 = 1,
    //        Millisecond100 = 2,
    //        Millisecond500 = 3,
    //        Second = 4,
    //        Second5 = 5,
    //        Second30 = 6,
    //        Minute = 7,
    //        Hour = 8
    //    }

    //    public enum States
    //    {
    //        Started = 0,
    //        Paused = 1
    //    }
    //    #endregion

    //    #region zh-CHS 私有成员变量 | en Private Member Variables
    //    private long                m_LastCall;
    //    private long                m_Delay;
    //    private States              m_State;
    //    private Priorities          m_Priority;
    //    #endregion

    //    #region zh-CHS 构造和初始化和清理 | en Constructors and Initializers and Dispose
    //    public ServerSliceTimer(Priorities priorities, double delay)
    //    {
    //        m_State = ServerSliceTimer.States.Paused;
    //        m_Delay = (long)delay;
    //        m_Priority = priorities;
    //        m_LastCall = (long)DateTime.Now.Subtract(BaseWorld.StartingTime).TotalMilliseconds;
    //    }

    //    public ServerSliceTimer(double delay)
    //    {
    //        m_State = ServerSliceTimer.States.Paused;
    //        m_Delay = (long)delay;

    //        // 缺省只有6种时间片
    //        if (delay < 100)
    //            m_Priority = ServerSliceTimer.Priorities.Millisecond10;
    //        else if (delay < 1000)
    //            m_Priority = ServerSliceTimer.Priorities.Millisecond100;
    //        else if (delay < 5000)
    //            m_Priority = ServerSliceTimer.Priorities.Second;
    //        else if (delay < 10000)
    //            m_Priority = ServerSliceTimer.Priorities.Second5;
    //        else if (delay > 3600000)
    //            m_Priority = ServerSliceTimer.Priorities.Hour;
    //        else
    //            m_Priority = ServerSliceTimer.Priorities.Second30;

    //        m_LastCall = (long)DateTime.Now.Subtract(BaseWorld.StartingTime).TotalMilliseconds;
    //    }
    //    #endregion

    //    #region zh-CHS 属性 | en Properties
    //    public States State 
    //    {
    //        get { return this.m_State; }
    //        set { this.m_State = value; }
    //    }
    //    #endregion

    //    #region zh-CHS 公开的函数 | en Class Public Methods
    //    public virtual void OnTick()
    //    {
    //    }

    //    public void Start()
    //    {
    //        m_State = ServerSliceTimer.States.Started;
    //        BaseWorld.Timers[(int)m_Priority].Enqueue(this);
    //    }

    //    public void Restart()
    //    {
    //        m_LastCall = (long)DateTime.Now.Subtract(BaseWorld.StartingTime).TotalMilliseconds;
    //    }

    //    public bool Slice(long timeTotal)
    //    {
    //        if (this.State == ServerSliceTimer.States.Paused)
    //            return false;

    //        long l_StartingTimeToLastCall = timeTotal - m_LastCall;
    //        if (l_StartingTimeToLastCall > m_Delay)
    //        {
    //            m_LastCall = l_StartingTimeToLastCall;

    //            OnTick();

    //            if (this.State == ServerSliceTimer.States.Paused)
    //                return false;
    //        }

    //        return true;
    //    }

    //    public void Stop()
    //    {
    //        m_State = ServerSliceTimer.States.Paused;
    //    }
    //    #endregion
    //}
}
#endregion

